package com.cmcc.pcap.packet.udp;

import java.util.Date;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cmcc.packet.entity.UdpEntity;
import com.cmcc.pcap.packet.udp.udp.xdr.UdpXdrGenerate;

/**
 * @Auther: zhida wei
 * @Date: 2019/6/17 18:06
 * @Description:
 */
public class UdpHandler extends UdpProtocolHandler<UdpEntity> {
    private static Logger logger = LogManager.getLogger(com.cmcc.pcap.packet.udp.UdpHandler.class);
    private UdpXdrGenerate uxg;

    public UdpHandler() {
        uxg =  new UdpXdrGenerate();
    }

    @Override
    public List<UdpEntity> handle(UdpConnection udpConnection, String taskId) {

        logger.debug("start execute udp packet handler");

        logger.debug(new Date(udpConnection.lastPacketTime));//最后一个packet的处理时间(注:非抓包时间)
        long pcapTimestamp  = udpConnection.lastPacketTime;//pcap的timestamp的单位是秒，这里需要转成毫秒
        logger.debug(new Date(pcapTimestamp));//最后一个packet的抓包时间


        List<UdpEntity> xdrudpEntityList = uxg.generate(udpConnection,taskId);
        logger.debug("this connection <"+udpConnection.connectionKey+"> save into udp packet entity !");

        return xdrudpEntityList;

    }
}
